package com.mbc.rmt.manager;

import java.util.HashMap;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;

import com.mbc.common.CommonSingleton;
import com.mbc.common.manager.AbstractMgr;
import com.mbc.rmt.dao.RemittanceDAOFactory;
import com.mbc.rmt.dao.SpecialReportDAO;
import com.mbc.rmt.entities.CashCollectionRpt;
import com.mbc.rmt.entities.CashPaymentCollectionRpt;
import com.mbc.rmt.entities.CashReceivedCollectionRpt;

public class SpecialReportMgr  extends AbstractMgr{
	
	public SpecialReportDAO specialreportdao;
	
	public SpecialReportMgr(){		
	}

	public SpecialReportMgr(String sessionId) {
		this.sessionId = sessionId;
	}
	
	//Cash Collection
	public JasperPrint prepareCashCollectionReport(CashCollectionRpt info)
			throws Exception {
		openConnection();
		JasperPrint l_jsPrint = null;
		try {
			specialreportdao = RemittanceDAOFactory.getSpecialReportDAO(dbManager.getConnection());
			JRResultSetDataSource l_jrRS = new JRResultSetDataSource(specialreportdao.prepareCashCollectionReport(info));
			JasperReport l_jsRpt = null;
				l_jsRpt = (JasperReport) JRLoader
					.loadObjectFromFile(CommonSingleton.ABSOLUTE_PATH +"reports/CashCollectionRpt.jasper");
	
			HashMap<String, Object> l_params = new HashMap<String, Object>();
			l_params.put("companyname", "mbc");
			l_jsPrint = JasperFillManager.fillReport(l_jsRpt, l_params, l_jrRS);

		} catch (JRException je) {
			throw je;
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}

		return l_jsPrint;

	}
	
	//End Cash Collection
	
	//Cash Received Collection
	public JasperPrint prepareCashRecrivedCollectionReport(CashReceivedCollectionRpt info)
			throws Exception {
		openConnection();
		JasperPrint l_jsPrint = null;
		try {
			specialreportdao = RemittanceDAOFactory.getSpecialReportDAO(dbManager.getConnection());
			JRResultSetDataSource l_jrRS = new JRResultSetDataSource(specialreportdao.prepareCashRecrivedCollectionReport(info));
			JasperReport l_jsRpt = null;
				l_jsRpt = (JasperReport) JRLoader
					.loadObjectFromFile(CommonSingleton.ABSOLUTE_PATH +"reports/CashReceivedCollectionRpt.jasper");
	
			HashMap<String, Object> l_params = new HashMap<String, Object>();
			l_params.put("companyname", "mbc");
			l_jsPrint = JasperFillManager.fillReport(l_jsRpt, l_params, l_jrRS);

		} catch (JRException je) {
			throw je;
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}

		return l_jsPrint;

	}	
	//End Cash Received Collection
	
	//Start Cash Payment Collection Rpt 
	public JasperPrint prepareCashPaymentCollectionReport(CashPaymentCollectionRpt info)
			throws Exception {
		openConnection();
		JasperPrint l_jsPrint = null;
		try {
			specialreportdao = RemittanceDAOFactory.getSpecialReportDAO(dbManager.getConnection());
			JRResultSetDataSource l_jrRS = new JRResultSetDataSource(specialreportdao.prepareCashPaymentCollectionReport(info));
			JasperReport l_jsRpt = null;
				l_jsRpt = (JasperReport) JRLoader
					.loadObjectFromFile(CommonSingleton.ABSOLUTE_PATH +"reports/CashPaymentCollectionRpt.jasper");
	
			HashMap<String, Object> l_params = new HashMap<String, Object>();
			l_params.put("companyname", "mbc");
			l_jsPrint = JasperFillManager.fillReport(l_jsRpt, l_params, l_jrRS);

		} catch (JRException je) {
			throw je;
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}

		return l_jsPrint;

	}	
	//End Cash Payment Collection Rpt
}
